home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2009 February
/
PCWFEB09.iso
/
Software
/
Resources
/
Chat & Communication
/
Digsby build 37
/
digsby_setup.exe
/
lib
/
compiler
/
visitor.pyo
(
.txt
)
< prev
Wrap
Python Compiled Bytecode
|
2008-10-13
|
3KB
|
97 lines
# Source Generated with Decompyle++
# File: in.pyo (Python 2.5)
from compiler import ast
class ASTVisitor:
VERBOSE = 0
def __init__(self):
self.node = None
self._cache = { }
def default(self, node, *args):
for child in node.getChildNodes():
self.dispatch(child, *args)
def dispatch(self, node, *args):
self.node = node
klass = node.__class__
meth = self._cache.get(klass, None)
if meth is None:
className = klass.__name__
meth = getattr(self.visitor, 'visit' + className, self.default)
self._cache[klass] = meth
return meth(node, *args)
def preorder(self, tree, visitor, *args):
self.visitor = visitor
visitor.visit = self.dispatch
self.dispatch(tree, *args)
class ExampleASTVisitor(ASTVisitor):
examples = { }
def dispatch(self, node, *args):
self.node = node
meth = self._cache.get(node.__class__, None)
className = node.__class__.__name__
if meth is None:
meth = getattr(self.visitor, 'visit' + className, 0)
self._cache[node.__class__] = meth
if self.VERBOSE > 1:
print 'dispatch', className,
if not meth or meth.__name__:
pass
print ''
if meth:
meth(node, *args)
elif self.VERBOSE > 0:
klass = node.__class__
if not self.examples.has_key(klass):
self.examples[klass] = klass
print
print self.visitor
print klass
for attr in dir(node):
if attr[0] != '_':
print '\t', '%-12.12s' % attr, getattr(node, attr)
continue
print
return self.default(node, *args)
_walker = ASTVisitor
def walk(tree, visitor, walker = None, verbose = None):
if walker is None:
walker = _walker()
if verbose is not None:
walker.VERBOSE = verbose
walker.preorder(tree, visitor)
return walker.visitor
def dumpNode(node):
print node.__class__
for attr in dir(node):
if attr[0] != '_':
print '\t', '%-10.10s' % attr, getattr(node, attr)
continue